$(function(){
	var use = document.getElementById("register_use")
	var oul =document.getElementById("use_ul")
	var pas = document.getElementById("register_mima")
	var arr=["","@qq.com","@mail.com","@126.com","@163.com","@live.com","@hotmail.com","@sohu.com","@sina.com"]
	var cuo = document.getElementById("cuo")
	var timer =null
	var arr2 = ["false","false"]
	//自动登录
//	var arr3 =[]
//	var arr4 = []
//	if($.cookie()){
//		var $str = $.cookie()
//		$.each($str,function(index,value){
//			arr3.push(index)
//			arr4.push(value)
//		})
//		use.value = arr3[0]
//		 
//		pas.value = arr4[0]
//	} 
	use.oninput=function(){
		oul.style.display = "block"
		oul.innerHTML =""
		clearInterval(timer)
		timer=setInterval(function(){
			var ls = use.value
			for(var i =0;i <8;i++){
			var oli = document.createElement("li")
			oli.innerHTML = ls+""+arr[i]
			oli.onclick = function(){
				use.value = this.innerHTML
				oul.style.display = "none"
			}
			oli.onmouseover = function(){
				for(var i =0;i<8;i++){
					oul.children[i].style.background =""
				}
				this.style.background="red"
			}
			oul.appendChild(oli)
			if(i == 7){
				clearInterval(timer)
			}
		}
			ls = ""
		},500)	  
	}
	
		use.onblur = function(){
			
			 if(use.value.split("").length < 6){
				cuo.innerHTML = "不能少于6位数"
			}else {
				var zheng =/^(13[0-9]|14[5|7]|15[0|1|2|3|5|6|7|8|9]|18[0|1|2|3|5|6|7|8|9])\d{8}$/
				if(zheng.test(use.value) == false){
					cuo.innerHTML = "请输入正确手机格式"
					arr2[1] = "false"
				}else{
					cuo.innerHTML = "正确"
					arr2[0] = "true"
					console.log(arr2)
				}
			}
			  
		}
		var cuoma = document.getElementById("cuoma")
		
		pas.onblur = function(){
			var ls = pas.value
			var yan = /^[0-9a-zA-Z]{6,20}$/
			if(yan.test(ls) == false){
				cuoma.innerHTML = "密码不正确"
				arr2[1] = false
			}
			if(yan.test(ls) == true){
				cuoma.innerHTML = "正确"
				arr2[1] = "true"
				console.log(arr2)
			}
		}
	var form = document.getElementById("reg_form")
	var btn = document.getElementById("register_btn")
	 	btn.onclick = function(){
	 		if( arr2[0] == "true" && arr2[1] == "true"){
	 			//console.log(1)
	 			$.cookie(use.value,pas.value,{path:'/',expires:7})
	 			 return true
	 			
	 		}else{
	 			//console.log(2)
	 			return false
	 		}
	 		
	 	}
	 
	  
	
})
